<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
    <script>
        //给定 nums = [2, 7, 11, 15], target = 9
        // 因为 nums[0] + nums[1] = 2 + 7 = 9
        // 所以返回 [0, 1]
        /**
         * @param {number[]} nums
         * @param {number} target
         * @return {number[]}
         */
        var arr = [2, 7, 11, 15];
        var twoSum = function(nums, target) {
            var res = target;
            for (var i = 0; i < nums.length; i++) {
                for (var j = i + 1; j < nums.length; j++) {
                    if (nums[i] + nums[j] == target) {
                        return [nums[i], nums[j]]
                    }
                }
            }
        };
        console.log(twoSum(arr, 9)); //
    </script>
</body>

</html>